from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
import time

testCase = "DBshop006订单管理删除订单"

firefox=openBrowser(urlAdmin)     #调用函数打开后台网址
DBshopLoginAdmin(firefox)         #调用函数登录

# 1.点击销售管理订单管理界面。
DBshopEnterMenu2(firefox,"销售管理","订单管理")

# 2.在订单状态点击已取消一栏，点击“搜索”按钮一款，勾选之后，选择删除，点击提交操作。
firefox.find_element_by_id("order_state").click()
firefox.find_element_by_xpath("//option[@value='0']").click()
firefox.find_element_by_xpath("(//button)[1]").click()
time.sleep(2)

#取订单数值1
s1 = firefox.find_element_by_xpath('//strong').text
l = '订单数：'
r = '\)'
w = reGetString(s1,l,r)
# print(w)

# 3.删除成功
firefox.find_element_by_link_text("编辑查看").click()
firefox.find_element_by_link_text("删除订单").click()
firefox.switch_to.alert.accept()

#取订单数值2
DBshopEnterMenu2(firefox,"销售管理","订单管理")
firefox.find_element_by_id("order_state").click()
firefox.find_element_by_xpath("//option[@value='0']").click()
firefox.find_element_by_xpath("(//button)[1]").click()
time.sleep(2)
s2=firefox.find_element_by_xpath('//strong').text
n = reGetString(s2,l,r)
# print(n)

# 断言
if int(w)-int(n)==1:#1是预期值
    writeLog("%s 测试通过" % testCase)
else:
    writeLog("%s 测试不通过" % testCase)
    getPhoto(firefox)
firefox.quit()